const users = [];

function userJoin(id, name, room) {
    const user = { id, name, room }
    users.push(user);
    return user;
}

//去除相同的用户
function userLeave(id) {
    const index = users.findIndex(user => user.id === id);
    if (index !== -1) {
        return users.splice(index, 1)[0];
    }
}

function getRoomUsers(room) {
    return users.filter(user => user.room === room);
}



//导出
module.exports = {
    userJoin,
    userLeave,
    getRoomUsers,

}